package org.cloudbus.cloudsim.examples.power.parallel.helper;

import java.text.DecimalFormat;
import java.util.List;

import org.cloudbus.cloudsim.examples.power.Constants;
import org.cloudbus.cloudsim.examples.power.parallel.MainFieldInfo;

public class StatisticalRuntime {

	private List<MainFieldInfo> list;

	public StatisticalRuntime(List<MainFieldInfo> list) {
		super();
		this.list = list;
	}

	public int getJobBaseValue(double down, double up) {
		down = down * Constants.parseDay;
		up = up * Constants.parseDay;
		int count = 0;
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getRuntime() >= down
					&& list.get(i).getRuntime() != Double.parseDouble("-1")
					&& list.get(i).getRuntime() < up) {
				count++;
			}
		}
		return count;
	}

	public String getJobBasePercent(double down, double up) {
		int numberJob = getJobBaseValue(down, up);
		DecimalFormat decimalFormat = new DecimalFormat("#.##");
		return decimalFormat.format((double) numberJob / list.size() * 100);

	}

	public int getJobUndefined() {
		int count = 0;
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getRuntime() == -1) {
				count++;
			}
		}
		return count;
	}
	
	public String getJobUndefinedPercent() {
		int numberJob = getJobUndefined();
		DecimalFormat decimalFormat = new DecimalFormat("#.##");
		return decimalFormat.format((double) numberJob / list.size() * 100);
	}

}
